package middleware

import (
	"fmt"
	"go-gateway-learn/golang_common/lib"

	"github.com/gin-gonic/gin"
)

func IPAuth() gin.HandlerFunc{
	return func(c *gin.Context) {
		isMatched := false
		for _, host := range lib.GetStringSliceConf("base.http.allow_ip"){
			if c.ClientIP() ==host{
				isMatched = true
			}
		}
		if !isMatched{
			ResponseError(c, InternalErrorCode, fmt.Errorf("%v, not in SPList",c.ClientIP()))
			c.Abort()
			return
		}
		c.Next()
	}
}